﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using API.Helpers;
using API.IServices;
using API.Models;
using API.Services;
using POS.Models;

namespace POS.Controllers
{
    public class FoodOrderController : BaseController
    {
        //
        // GET: /FoodOrder/

        public ActionResult Index()
        {
            return View();
        }

        private readonly IFoodService _foodService = DependencyInjectionHelper.Resolve<IFoodService>();
        private readonly IFoodOrderService _foodOrderService = DependencyInjectionHelper.Resolve<IFoodOrderService>();

        public FoodOrderController()
        {
            _foodService = new FoodService();
            _foodOrderService = new FoodOrderService();
        }

        [HttpGet]
        public JsonNetResult GetFoodOrderListing(string sort)
        {

            //When binding the grid, keep track of the isDeleted field without displaying the isDeleted field.
            //New entries in this grid should default to isDeleted=false
            var query = _foodOrderService.Get().OrderByDescending(c => c.Created).Where(c => c.TableOrder.WaiterId == WaiterId);
            var count = query.Count();
					
            return new JsonNetResult(new
            {
                Data = query.ToList(),
                TotalRecords = count
            });
        }


        public ActionResult SendOrder(int tableOrderId)
        {
            throw new NotImplementedException();


        }

        public ActionResult SaveOrder(int tableOrderId)
        {
           // //save all entries in grid using
           //List<FoodOrder> entriesInGrid = entries in grid;

           // foreach (var foodOrder in entriesInGrid)
           // {
           //     var savedOrder = _foodOrderService.Save(foodOrder);
           // }

            throw new NotImplementedException();
        }

    }
}
